package com.zpark.springboot02;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 数学黑洞
 * 复杂度为：
 */
public class BlackHole {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入您想测试的数据：");
        String input = sc.nextLine();
        int count = 0;
        while (true) {
            char[] array = input.toCharArray();
            Arrays.sort(array);
            int min = Integer.parseInt(new String(array));
            char[] newArray = new char[array.length];
            for (int i = 0; i < array.length; i++) {
                newArray[array.length - i - 1] = array[i];
            }
            int max = Integer.parseInt(new String(newArray));
            count++;
            if (max - min == 6174) {
                System.out.println("最多"+count+"次得到6174");
                break;
            } else {
                input = (max - min) + "";
            }
        }

    }
}

